<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------

namespace app\controller\admin\v1\recruit;

use app\controller\admin\AuthController;
use app\model\v1\recovery\RecoveryQuestionCate;
use app\model\v1\recovery\RecoveryReport;
use app\model\v1\recovery\SystemOperationLog;
use app\model\v1\recruit\RecruitCompany;
use app\model\v1\recruit\RecruitCompanyAccount;
use app\model\v1\recruit\RecruitFirmType;
use app\model\v1\recruit\RecruitIndustry;
use app\model\v1\recruit\RecruitJob;
use app\model\v1\recruit\RecruitJobCate;
use app\model\v1\recruit\RecruitJobPoints;
use app\model\v1\recruit\RecruitJobSeeker;
use app\model\v1\recruit\RecruitLanguage;
use app\model\v1\recruit\RecruitPersonageAuthentication;
use app\Request;
use app\services\article\ArticleCategoryServices;
use crmeb\services\CacheService;
use think\facade\App;
use think\filesystem\driver\Local;

/**
 * 求职招聘管理
 * Class ArticleCategory
 * @package app\controller\admin\v1\cms
 */
class RecruitCollection extends AuthController
{
    protected $model;

    public function __construct(App $app, RecruitJobSeeker $model)
    {
        parent::__construct($app);
        $this->model = $model;
    }

    /**
     * 求职招聘后台 - 获取人才管理列表
     * @return mixed
     */
    public function getJobUserList (Request $request)
    {
        $param = $request->param();
        $param['page'] = input('param.page', 1);
        $param['limit'] = input('param.limit', 10);

        $data = RecruitJobSeeker::getJobUserList($param);
        return $this->success($data);
    }


    /**
     * 求职招聘后台 - 获取人才管理列表 - 获取搜索项数据
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getJobUserData (Request $request)
    {
        $param = $request->param();

        $data = RecruitJobSeeker::getJobUserData($param);
        return $this->success($data);
    }


    /**
     * 求职招聘后台 - 获取人才管理列表 - 获取行业分类列表数据
     * @param Request $request
     * @return void
     */
    public function getIndustryConfigList(Request $request)
    {
        $param = $request->param();
        $id = $param["id"] ?? 0;
        $data = RecruitIndustry::getIndustryData($id);

        return $this->success($data);
    }


    /**
     * 获取企业列表
     * @param Request $request
     * @return mixed
     */
    public function getRecruitCompanyData(Request $request)
    {
        $param = $request->param();
        $id = $param["id"] ?? 0;
        $data = RecruitCompany::getRecruitCompanyData($id);

        return $this->success($data ? $data->toArray() : []);
    }




    /**
     * 求职招聘后台 - 获取人才管理列表 - 查看
     * @return mixed
     * @throws \FormBuilder\Exception\FormBuilderException
     */
    public function getJobUserDetail(Request $request)
    {
        $param = $request->param();
        if(empty($param["id"])) return $this->fail('id不能为空');

        $detail = RecruitJobSeeker::getJobUserDetail($param);

        return $this->success($detail ? $detail->toArray() : []);
    }


    /**
     * 求职招聘后台 - 获取人才管理列表 - 批量删除
     * @return mixed
     */
    public function deleteJobUser(Request $request)
    {
        $param = $request->post();
        if(empty($param['ids'])) return $this->fail('ids不能为空');

        $res = RecruitJobSeeker::whereIn("id", explode(",", $param['ids']))->update(['delete_at'=>date("Y-m-d H:i:s")]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['ids']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'recruit','人才管理列表','deleteJobUser','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 求职招聘后台 - 获取人才管理列表 - 启用禁用
     * @param Request $request
     * @return mixed
     */
    public function enableJobUser(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecruitJobSeeker::enableJobUser($param);

        return $this->success($msg);
    }



    /**
     * 求职招聘后台 - 获取岗位管理列表
     * @param $id
     * @return mixed
     * @throws \FormBuilder\Exception\FormBuilderException
     */
    public function getRecruitJobList(Request $request)
    {
        $param = $request->param();
        $param['page'] = input('param.page', 1);
        $param['limit'] = input('param.limit', 10);

        $data = RecruitJob::getRecruitJobList($param);

        return $this->success($data);
    }



    /**
     * 获取岗位管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateRecruitCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['position'])) return $this->fail('position不能为空');
        if(empty($param['industry_id'])) return $this->fail('industry_id不能为空');

        $param["admin_id"] = $this->adminId;
        $res = RecruitJob::updateRecruitJob($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：职位名称：{$param['position']}.";
        SystemOperationLog::addSystemLog($admin_id,'recruit','岗位管理列表','updateRecruitCate','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('编辑成功');
        }
        return $this->fail('编辑失败');
    }


    /**
     * 求职招聘后台 - 获取岗位管理列表 - 查看
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getRecruitJobDetail(Request $request)
    {
        $param = $request->param();
        if(empty($param["id"])) return $this->fail('id不能为空');

        $detail = RecruitJob::getRecruitJobDetail($param);

        return $this->success($detail ? $detail->toArray() : []);
    }


    /**
     * 获取岗位管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateRecruitJob(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['position'])) return $this->fail('position不能为空');
        if(empty($param['industry_id'])) return $this->fail('industry_id不能为空');

        $param["admin_id"] = $this->adminId;
        $res = RecruitJob::updateRecruitJob($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：职位名称：{$param['position']}.";
        SystemOperationLog::addSystemLog($admin_id,'recruit','岗位管理列表','updateRecruitCate','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('编辑成功');
        }
        return $this->fail('编辑失败');
    }


    /**
     * 求职招聘后台 - 获取岗位管理列表 - 批量删除
     * @param Request $request
     * @return mixed
     */
    public function deleteRecruitJob(Request $request)
    {
        $param = $request->post();
        if(empty($param['ids'])) return $this->fail('ids不能为空');

        $res = RecruitJob::whereIn("id", explode(",", $param['ids']))->update(['delete_at'=>date("Y-m-d H:i:s")]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['ids']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'recruit','岗位管理列表','deleteRecruitJob','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }



    /**
     * 求职招聘后台 - 获取岗位管理列表 - 启用禁用
     * @param Request $request
     * @return mixed
     */
    public function enableRecruitJob(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecruitJob::enableRecruitJob($param);

        return $this->success($msg);
    }


    /**
     * 求职招聘后台 - 企业认证管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getRecruitCompanyList(Request $request)
    {
        $param = $request->param();
        $param['page'] = input('param.page', 1);
        $param['limit'] = input('param.limit', 10);

        $data = RecruitCompany::getRecruitCompanyList($param);

        return $this->success($data);
    }


    /**
     * 企业认证管理列表 - 查看
     * @param Request $request
     * @return mixed
     */
    public function getRecruitCompanyDetail(Request $request)
    {
        $param = $request->param();
        if(empty($param["id"])) return $this->fail('id不能为空');

        $data = RecruitCompany::getRecruitCompanyDetail($param);

        return $this->success($data ? $data->toArray() : []);
    }


    /**
     * 主聊打管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateChatPhone(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['phone_count_config'])) return $this->fail('phone_count_config不能为空');

        $param["admin_id"] = $this->adminId;
        $res = RecruitCompany::updateChatPhone($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：主动打电话次数：{$param["phone_count_config"]}.";
        SystemOperationLog::addSystemLog($admin_id,'recruit','主聊打管理列表','updateChatPhone','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('编辑成功');
        }
        return $this->fail('编辑失败');
    }





    /**
     * 求职招聘后台 - 企业认证管理列表 - 审核按钮
     * @return void
     */
    public function enableCompanyState(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['audit_state'])) return $this->fail('audit_state不能为空');
        $msg = "通过";
        if($param["audit_state"] == 2){
            if(empty($param['refuse_reason'])) return $this->fail('refuse_reason原因描述不能为空');
            $msg = "不通过";
        }

        $res = RecruitCompany::enableCompanyState($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据审核为：{$msg}.";
        SystemOperationLog::addSystemLog($admin_id,'recruit','企业认证管理列表','enableCompanyState','审核',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }



    public function setCompanyCustomer(Request $request)
    {
        try {
            $param = $request->post();
            if (empty($param['id'])) return $this->fail('id不能为空');
            if (empty($param['kefu_id'])) return $this->fail('kefu_id不能为空');

            $res = RecruitCompany::setCompanyCustomer($param);
            if ($res >= 0) {
                return $this->success('success');
            }

            return $this->fail('fail');
        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }


    /**
     * 求职招聘后台 - 举报管理列表
     * @param Request $request
     * @return void
     */
    public function getRecruitReportList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = RecruitCompany::getReportList($param);

        return $this->success($data);
    }


    /**
     * 求职招聘后台 - 举报管理列表 - 查看
     * @return void
     */
    public function getRecruitReportDetail(Request $request)
    {
        $param = $request->param();
        if(empty($param["id"])) return $this->fail('id不能为空');

        $detail = RecruitCompany::getRecruitReportDetail($param);

        return $this->success($detail ? $detail->toArray() : []);
    }


    /**
     * 求职招聘后台 - 行业管理列表
     * @param Request $request
     * @return mixed
     */
    public function getRecruitIndustryList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = RecruitIndustry::getRecruitIndustryList($param);

        return $this->success($data);
    }


    /**
     * 求职招聘后台 - 行业管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addRecruitIndustry(Request $request)
    {
        $param = $request->post();
        if(empty($param['industry_name'])) return $this->fail('industry_name行业名称不能为空');

        $find = RecruitIndustry::where(["pid"=>$param["pid"], "industry_name"=>$param["industry_name"]])->find();
        if(!empty($find)) return $this->fail('不能重复添加！');

        $res = RecruitIndustry::addRecruitIndustry($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }


    /**
     * 行业管理列表 - 启用禁用
     * @param Request $request
     * @return mixed
     */
    public function enableRecruitIndustry(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecruitIndustry::enableRecruitIndustry($param);

        return $this->success($msg);
    }

    /**
     * 行业管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateRecruitIndustry(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['pid'])) return $this->fail('pid不能为空');
        if(empty($param['industry_name'])) return $this->fail('industry_name行业名称不能为空');

        $res = RecruitIndustry::updateRecruitIndustry($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：行业名称： {$param['industry_name']}.";
        SystemOperationLog::addSystemLog($admin_id,'recruit','行业管理列表','updateRecruitIndustry','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }



    /**
     * 行业管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function delRecruitIndustry(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RecruitIndustry::where("id", $param["id"])->update(["delete_at" => time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'recruit','行业管理列表','delRecruitIndustry','删除',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }


    /**
     * 求职招聘后台 - 类型配置管理列表
     * @param Request $request
     * @return void
     */
    public function getQuestionCateList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = RecruitCompany::getQuestionCateList($param);

        return $this->success($data);
    }


    /**
     * 类型配置管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addQuestionCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['type']))   return $this->fail('type类型id不能为空');
        if(empty($param['cate_name']))   return $this->fail('cate_name属性名称为空');

        $param["admin_id"] = $this->adminId;
        $res = RecruitCompany::addQuestionCate($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }


    /**
     * 类型配置管理列表 - 编辑
     * @param Request $request
     * @return void
     */
    public function updateQuestionCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['type'])) return $this->fail('type类型id不能为空');
        if(empty($param['cate_name'])) return $this->fail('cate_name属性名称为空');

        $param["admin_id"] = $this->adminId;
        $res = RecruitCompany::updateQuestionCate($param);
        if($res >= 0){
            return $this->success('编辑成功');
        }

        return $this->fail('编辑失败');
    }


    /**
     * 属性库管理列表 - 删除
     * @return void
     */
    public function deleteQuestionCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RecoveryQuestionCate::where("id", $param['id'])->update(['delete_time'=>time()]);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 属性库管理列表 - 启用禁用
     * @return void
     */
    public function enableQuestionCateStatus(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecoveryQuestionCate::enableQuestionCateStatus($param);

        return $this->success($msg);
    }


    /**
     * 求职招聘后台 - 常用语管理列表
     * @return mixed
     */
    public function getRecruitLanguageList(Request $request)
    {
        $param = $request->param();
        $param['page'] = input('param.page', 1);
        $param['limit'] = input('param.limit', 10);

        $data = RecruitLanguage::getRecruitLanguageData($param);
        return $this->success($data);
    }


    /**
     * 常用语管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateRecruitLanguage(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['content'])) return $this->fail('content不能为空');
        if(empty($param['sort'])) return $this->fail('sort不能为空');

        $param["admin_id"] = $this->adminId;
        $res = RecruitLanguage::updateRecruitLanguage($param);
        if($res >= 0){
            return $this->success('编辑成功');
        }

        return $this->fail('编辑失败');
    }


    /**
     * 常用语管理列表 - 删除
     * @return void
     */
    public function deleteRecruitLanguage(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RecruitLanguage::where("id", $param['id'])->update(['delete_time'=>time()]);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 常用语管理列表 - 启用禁用
     * @return void
     */
    public function enableRecruitLanguage(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecruitLanguage::enableRecruitLanguage($param);

        return $this->success($msg);
    }



    /**
     * 类型配置管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addRecruitLanguage(Request $request)
    {
        $param = $request->post();
        if(empty($param['content'])) return $this->fail('content不能为空');
        if(empty($param['sort'])) return $this->fail('sort不能为空');

        $res = RecruitLanguage::addRecruitLanguage($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }




    /**
     * 求职招聘后台 - 配置管理列表
     * @return mixed
     */
    public function getJobCateList(Request $request)
    {
        $param = $request->param();
        $param['page'] = input('param.page', 1);
        $param['limit'] = input('param.limit', 10);

        $data = RecruitJobCate::getJobCateList($param);
        return $this->success($data);
    }


    /**
     * 配置管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addJobCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['job_name'])) return $this->fail('job_name不能为空');
        if(empty($param['type'])) return $this->fail('type不能为空');
        if(empty($param['sort'])) return $this->fail('sort不能为空');

        $res = RecruitJobCate::addJobCate($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }




    /**
     * 配置管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateJobCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['job_name'])) return $this->fail('job_name不能为空');
        if(empty($param['type'])) return $this->fail('type不能为空');
        if(empty($param['sort'])) return $this->fail('sort不能为空');

        $res = RecruitJobCate::updateJobCate($param);
        if($res >= 0){
            return $this->success('编辑成功');
        }

        return $this->fail('编辑失败');
    }


    /**
     * 配置管理列表 - 删除
     * @return void
     */
    public function deleteJobCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RecruitJobCate::where("id", $param['id'])->update(['delete_time'=>time()]);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 配置管理列表 - 启用禁用
     * @return void
     */
    public function enableJobCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecruitJobCate::enableJobCate($param);

        return $this->success($msg);
    }



    /**
     * 配置管理列表 - 获取行业分类列表数据
     * @param Request $request
     * @return void
     */
    public function getJobCateData(Request $request)
    {
        $data = RecruitJobCate::getJobCateData();
        return $this->success($data);
    }


    /**
     * 获取用户客服
     * @param Request $request
     * @return mixed
     */
    public function getCustomerUserList(Request $request)
    {
        $param = $request->post();

        $data = RecruitCompany::getCustomerUserList($param);

        return $this->success($data);
    }



    /**
     * 求职招聘后台 - 人才认证管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getRecruitAuthentList(Request $request)
    {
        $param = $request->param();
        $param['page'] = input('param.page', 1);
        $param['limit'] = input('param.limit', 10);

        $data = RecruitPersonageAuthentication::getRecruitAuthentList($param);

        return $this->success($data);
    }


    /**
     * 人才认证管理列表 - 查看
     * @param Request $request
     * @return mixed
     */
    public function getRecruitAuthentDetail(Request $request)
    {
        $param = $request->param();
        if(empty($param["id"])) return $this->fail('id不能为空');

        $data = RecruitPersonageAuthentication::getRecruitAuthentDetail($param);

        return $this->success($data ? $data->toArray() : []);
    }


    /**
     * 求职招聘后台 - 人才认证管理列表 - 审核按钮
     * @return void
     */
    public function enableRecruitAuthent(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['status'])) return $this->fail('status不能为空');
        if($param["status"] == 3){
            if(empty($param['refuse_reason'])) return $this->fail('refuse_reason原因描述不能为空');
        }

        $res = RecruitPersonageAuthentication::enableRecruitAuthent($param);
        if($res >= 0){
            return $this->success('success');
        }

        return $this->fail('fail');
    }




    /**
     * 求职招聘后台 - 企业账号管理列表
     * @param Request $request
     * @return mixed
     */
    public function getCompanyAccountList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = RecruitCompanyAccount::getCompanyAccountList($param);

        return $this->success($data);
    }


    /**
     * 企业账号管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addCompanyAccount(Request $request)
    {
        $param = $request->post();
        if(empty($param['company_account'])) return $this->fail('company_account企业账号不能为空');

        $find = RecruitCompanyAccount::where(["pid"=>$param["pid"], "company_account"=>$param["company_account"]])->find();
        if(!empty($find)) return $this->fail('不能重复添加！');

        $param["admin_id"] = $this->adminId;
        $res = RecruitCompanyAccount::addCompanyAccount($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }


    /**
     * 企业账号管理列表 - 启用禁用
     * @param Request $request
     * @return mixed
     */
    public function enableCompanyAccount(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecruitCompanyAccount::enableCompanyAccount($param);

        return $this->success($msg);
    }

    /**
     * 企业账号管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateCompanyAccount(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['company_account'])) return $this->fail('company_account企业账号不能为空');

        $find = RecruitCompanyAccount::where(["pid"=>$param["pid"], "company_account"=>$param["company_account"]])->find();
        if(!empty($find)) return $this->fail('不能重复添加！');

        $res = RecruitCompanyAccount::updateCompanyAccount($param);
        if($res >= 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }



    /**
     * 行业管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteCompanyAccount(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RecruitCompanyAccount::where("id", $param["id"])->update(["delete_at" => time()]);
        if($res >= 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }


    /**
     * 求职招聘后台 - 积分配置管理列表
     * @param Request $request
     * @return mixed
     */
    public function getJobPointsList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = RecruitJobPoints::getJobPointsList($param);

        return $this->success($data);
    }


    /**
     * 积分配置管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function createJobPoints(Request $request)
    {
        $param = $request->post();
        if(empty($param['points'])) return $this->fail('points不能为空');

        $find = RecruitJobPoints::where(["status"=>1, "points"=>$param["points"]])->find();
        if(!empty($find)) return $this->fail('不能重复添加！');

        $param["admin_id"] = $this->adminId;
        $res = RecruitJobPoints::createJobPoints($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }


    /**
     * 积分配置管理列表 - 启用禁用
     * @param Request $request
     * @return mixed
     */
    public function enableJobPoints(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecruitJobPoints::enableJobPoints($param);

        return $this->success($msg);
    }



    /**
     * 积分配置管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateJobPoints(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['points'])) return $this->fail('points不能为空');

        $find = RecruitJobPoints::where("id","<>",$param['id'])->where(["status"=>1, "points"=>$param["points"]])->find();
        if(!empty($find)) return $this->fail('积分值已存在！');

        $res = RecruitJobPoints::updateJobPoints($param);
        if($res >= 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }



    /**
     * 积分配置管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteJobPoints(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RecruitJobPoints::where("id", $param["id"])->update(["delete_time" => time()]);
        if($res >= 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }





    /**
     * 求职招聘后台 - 企业类型管理列表
     * @param Request $request
     * @return mixed
     */
    public function getRecruitFirmTypeList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = RecruitFirmType::getRecruitFirmTypeList($param);

        return $this->success($data);
    }


    /**
     * 求职招聘后台 - 企业类型管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addRecruitFirmType(Request $request)
    {
        $param = $request->post();
        if(empty($param['industry_name'])) return $this->fail('industry_name行业名称不能为空');

        $find = RecruitFirmType::where(["pid"=>$param["pid"], "name"=>$param["name"]])->find();
        if(!empty($find)) return $this->fail('不能重复添加！');

        $res = RecruitFirmType::addRecruitFirmType($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }


    /**
     * 企业类型管理列表 - 启用禁用
     * @param Request $request
     * @return mixed
     */
    public function enableRecruitFirmType(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecruitFirmType::enableRecruitIndustry($param);

        return $this->success($msg);
    }

    /**
     * 企业类型管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateRecruitFirmType(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['pid'])) return $this->fail('pid不能为空');
        if(empty($param['name'])) return $this->fail('name行业名称不能为空');

        $res = RecruitFirmType::updateRecruitFirmType($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：类型名称： {$param['name']}.";
        SystemOperationLog::addSystemLog($admin_id,'recruit','企业类型管理列表','updateRecruitFirmType','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }



    /**
     * 企业类型管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function delRecruitFirmType(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RecruitFirmType::where("id", $param["id"])->update(["delete_time" => time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'recruit','企业类型管理列表','delRecruitFirmType','删除',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }




    /**
     * 求职招聘后台 - 企业类型管理列表 - 获取类型数据
     * @param Request $request
     * @return void
     */
    public function getRecruitFirmTypeData(Request $request)
    {
        $param = $request->param();
        $id = $param["id"] ?? 0;
        $data = RecruitFirmType::getRecruitFirmTypeData($id);

        return $this->success($data);
    }




}
